package cn.com.ieds.util;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;

public class MakeJson {
    public static Map<String, Object> makeJson(Object object) throws IllegalAccessException,
            InstantiationException, InvocationTargetException {
        Class clazz = object.getClass();
        Method[] methods = clazz.getMethods();
        Object obj = clazz.newInstance();
        Map<String, Object> json = new HashMap<>();
        String key;
        Object value;
        for (Method method : methods) {
            //还未转换首字母小写，慎用
            key = method.getName().substring(method.getName().indexOf('t') + 1);
            value = method.invoke(obj);
            json.put(key,value);
        }

        return json;
    }
}
